<?php

Raise::load('core.RaiseCache');

/**
 * TestCoreRaiseCache
 * Testing unit of 'phpraise/core/RaiseCache.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseCache extends RaiseTest {

    public static function testClass(){

        self::assertClassExists('RaiseCache');
        self::assertInterfaceExists('IRaiseCache');
        self::assertClassImplements('RaiseCache', 'IRaiseCache');
        self::assertClassExtends('RaiseCache', 'RaiseObject');
        self::assertClassMethod('RaiseCache', array(
            'save',
            'load',
            'folder',
            'delete',
            'clear',
            'query',
            'file',
            'expiry'
        ));
    }

    public static function testSavingCache(){
        $cache = new RaiseCache(new RaiseTimeSpan(3600), 'testingCache');
        self::assertObjectClass($cache, 'RaiseCache');

        self::assertObjectClass($cache->file(), 'RaiseFile');

        $s = 'testing content';
        $cache->save($s);
        self::assertObjectClass($cache->expiry(), 'RaiseDateTime');
        self::assertTrue($cache->expiry()->toTimestamp() > time());

        $path = RaisePath::combine(RaiseCache::folder(), RaiseHashDigest::sha256($cache->id()));
        self::assertFileExist($path);
        self::assertStrictEqual($cache->load(), $s);

        unlink($path);
    }

}


